%Sequence Control - +1point +0.5points per urgent delivery
%Basically just reorganise the order based on priority

%call from another function as
%[urgent, standard] = prioritize(order)

function [urgent, standard] = prioritize(order)

    %order = [CupSize, Ncoffee, Ntea, Nsugar, Nespresso, IsUrgent]
    %order       1         2       3       4     5          6     
    %N-drinks is from 0 - N
    %type is either (coffee,tea) or (espresso) the other being 0
    
    urgent = {};
    standard = order;
    uN =1; %urgent order number
    cut = 0; %keeps track of how many items have been removed
             %so that the correct index can be taken from the array
             %even as it is being modified.
    for i = 2 : (order{1} + 1) %index(1) is N-Cups 
        
        if order{i}(6)%isurgent == 1
            
            %add current order to the urgent queue
            urgent{uN} = order{i};

            %remove current order from orders queue
            standard(i - cut) = [];
            
            cut = cut + 1;
            uN = uN + 1;
        end
    end
   standard(1) = []; 
%    urgent(1) = [];
   urgent = urgent.';

end

